﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Hzexe.Wechat.SharpSDK.Message.Request
{
    /// <summary>
    /// 文本消息
    /// </summary>
    [Serializable]
    [System.Xml.Serialization.XmlRoot("xml")]
    public class Message_In_Event : RequestMessageBase
    {
        /// <summary>
        /// 事件
        /// </summary>
        public string  Event { get; set; }

        public string EventKey { get; set; }

        /// <summary>
        /// 向子类克隆
        /// </summary>
        /// <typeparam name="T">事件类型对应的子类型</typeparam>
        /// <returns>子事件类型的深表副本</returns>
        public T CloneTo<T>() where T : Message_In_Event
        {
            T tp = default(T);
            byte[] data = System.Text.Encoding.UTF8.GetBytes(this.originalxmlstr);
            System.IO.MemoryStream stream = new System.IO.MemoryStream(data);
            var serializer = new XmlSerializer(typeof(T));
            stream.Position = 0;
            tp = serializer.Deserialize(stream) as T;
            tp.originalxmlstr = this.originalxmlstr;    //把原始的传入的xml字符放入对象内
            stream.Dispose();
            return tp;
        }
    }
}
